package util;

import domain.Point;
import domain.PointFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * @Author: sszheng
 * @Date: 2018/8/6 17:03
 */
public class ShuduUtil {
    public static boolean isPart(Point point, Point point1) {
        if(point.getX() / 3== point1.getX()/3 && point.getY() /3 == point1.getY() /3 ) {
            return true;
        }
        return false;
    }

    public static Integer getUniqueValue(Set<Integer> set) {
        if( set.size() == 1)  {
            for(Integer value : set) {
                return value;
            }
        }
        return null;
    }

    public static void print(List<Point> list) {
        System.out.println("=========================");
        for (int i = 0; i< list.size() ;i++) {
            if(i%9 == 0) {
                System.out.println();
            }
            if(list.get(i).getX() %3 == 0 && list.get(i).getY() == 0) {
                System.out.println("------------------------------------------------");
            }
            if(list.get(i).getEmpty()) {
                System.out.print("[" + list.get(i).getValue() + "]" + "  ");
            } else {
                System.out.print(" " + list.get(i).getValue() + "   ");
            }
            if(list.get(i).getY() %3 ==2) {
                System.out.print("| ");
            }
        }
        System.out.println();
    }

    public static List<Point> convert2List(String txt) {
        List<Point> list = new ArrayList<>();
        for(int i = 0; i < 9; i++) {
            for(int j = 0; j < 9; j++) {
                list.add(PointFactory.newInstance(i, j, txt));
            }
        }
        return list;
    }
}
